// 2025/11/7
// Z字形变换

class Solution {
public:
    string convert(string s, int numRows) {
        if(numRows <= 1) return s;
        int group = numRows + numRows - 2, n = s.size();
        string ans;
        for(int i = 0; i < n; i += group)
        {
            ans.push_back(s[i]);
        }
        for(int i = 1; i <= group / 2; i++)
        {
            for(int j = 0; j < n; j += group)
            {
                int l = j + i, r = j + group - i;
                if(l < n) ans.push_back(s[l]);
                if(r < n && r != l) ans.push_back(s[r]);
            }
        }
        return ans;
    }
};